class Solution:
    def isHappy(self, n: int) -> bool:
        record = set()
        while True:
            temp = self.getNumber(n)
            if temp in record:
                return False
            elif temp == 1:
                return True

            record.add(temp)

    def getNumber(self, n: int) -> int:
        new_num = 0
        while n:
            n, r = divmod(n, 10)
            new_num += r ** 2
        return new_num